The object's name, which is optional, must be a symbol. If this symbol is specified in the object definition expression, it is declared as a constant global variable into which the object is stored.
objectDefExpr ::= object [ symbol ] ( [ classesList ] ) objectBody end
classesList ::= simpleExpr [ , classesList ]
The body of an object definition expression has five optional clauses. These clauses are used to set keyword arguments, to define instance variables and methods, to initialize instance variables, and to insert a series of initial values into certain kinds of objects, such as collections. All five clauses are optional, but those that are present must be supplied in the specified order. The instance variables and instance methods clauses are exactly as defined under the class definition expression, on page 245. The others are defined below.
objectBody ::= [ initialization ] [ instVars ] [ instMethods ] \
[ settings ] [ contents ]
Every ScriptX object defines or inherits a version of the init
method, which takes keyword arguments and generally performs initialization tasks. The initialization section supplies the object's init
method with a list of keyword-value pairs. Although the initialization section is optional, many classes require some keyword arguments when a new object is created.
initialization ::= initList | empty
initList ::= initForm moreInitForms
initForm ::= symbol : simpleExpr
moreInitForms ::= [ endOfLine ]+ initList
| [ , initList ]*
The settings
clause in the object definition expression is in the same form as the initialization section. It allows a script to set initial values for instance variables that are writable, but are not set by the object's init
method. Any instance variables that are not initialized are set to undefined
.
settings ::= settings initList
The contents
clause in the object definition expression applies only to objects that implement the addToContents
method. In the core classes, addToContents
is defined as part of the Collection protocol. Use the contents
clause to add a series of values to a new Collection
object. Values are supplied as a comma or return separted list of simple expressions, and are added to the collection by the addToContents
method in the order in which they are supplied.
contents ::= contents contentsList
contentsList ::= simpleExpr moreContentForms
moreContentForms ::= [ endOfLine ]+ contentsList
| [ , contentsList ]*
This document is part of the ScriptX Language Guide, one of the volumes of the ScriptX Technical Reference Series. ScriptX is developed by the ScriptX Engineering Team at Apple Computer, successor to the Kaleida Engineering Team at Kaleida Labs, Inc.